package com.oxy.model.dao.impl;

import java.util.List;

import com.oxy.model.Pager;
import com.oxy.model.dao.MemberDao;
import com.oxy.model.po.MemberPO;
import com.oxy.model.dao.mapper.MemberPOMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;

public class MemberDaoImpl extends BaseDao implements MemberDao {
	
	@Autowired
	@Qualifier("memberPOMapper")
	private MemberPOMapper memberPOMapper;
	
	public MemberPOMapper getMemberPOMapper() {
		return memberPOMapper;
	}

	public void setMemberPOMapper(MemberPOMapper memberPOMapper) {
		this.memberPOMapper = memberPOMapper;
	}

	public long count() {
		long ret = 0;
		ret = memberPOMapper.count();
		return ret;
	}
	
	public List<MemberPO> list(Pager pager) {
		List<MemberPO> ret = null;
		ret = memberPOMapper.listForPager(pager);
		return ret;
	}

	public MemberPO selectByUserId(int uid) {
		MemberPO ret = null;
		ret = memberPOMapper.selectByPrimaryKey(uid);
		return ret;
	}

	public MemberPO selectByEmail(String email) {
		MemberPO ret = null;
		ret = memberPOMapper.selectByEmail(email);
		return ret;
	}

	public int insertMember(MemberPO member) throws DataAccessException {
		int ret = 0;
		ret = memberPOMapper.insert(member);
		return ret;
	}

	@Override
	public boolean loginByEmail(String email, String password) {
		boolean ret = false;
		int count = memberPOMapper.validateLoginByEmail(email, password);
		if(count == 1) {
			ret = true;
		}
		return ret;
	}
}
